<?php

class Crud_Auth_Adapter_Basic extends Zend_Auth_Adapter_DbTable
{
	const TABLE_NAME = 'admin_user';
	const COLUMN_IDENTITY = 'login';
	const COLUMN_PASSWORD = 'password';
	
	public function __construct()
	{
		$adapter = Db::getConnection();
		parent::__construct(
			$adapter, 
			self::TABLE_NAME, 
			self::COLUMN_IDENTITY, 
			self::COLUMN_PASSWORD
		);
	}

	/**
	 * Hash for password
	 * 
	 * @return Zend_Auth_Result
	 */
	public function authenticate()
	{
		$password = $this->getCredential();
        if ($password) {
        	$filter = new Filter_Password();
        	$password = $filter->filter($password);
        	$this->setCredential($password);
        }
	
		return parent::authenticate();
	}
	
    /**
     * getCredential() - get the credential value to be used
     *
     * @return  string $credential
     */
    public function getCredential()
    {
        return $this->_credential;
    }
}